use prefix increment on enums in brauniger_iq, garmin_txt, igc.
authortsteven4 <tsteven4@gmail.com>
Mon, 9 Jul 2018 01:21:28 +0000 (19:21 -0600)
committertsteven4 <tsteven4@gmail.com>
Mon, 9 Jul 2018 01:21:28 +0000 (19:21 -0600)
brauniger_iq.cc
garmin_txt.cc
igc.cc

index 17d6c570fc3980c81ceb8758113cba547f317904..606344b1acd99ac0cb440ac6ec9c5320f8d3a01e 100644 (file)
@@ -47,12 +47,16 @@ typedef enum {
   num_states
 } state_t;
 static state_t state;
-#if __cplusplus
-inline state_t operator++(state_t& rs, int)
+inline state_t& operator++(state_t& s) // prefix
 {
-  return rs = (state_t)((int)rs + 1);
+  return s = static_cast<state_t>(s + 1);
+}
+inline const state_t operator++(state_t& s, int) // postfix
+{
+  state_t ret(s);
+  s = ++s;
+  return ret;
 }
-#endif
 
 static const int reqd_bytes[num_states] = { 6, 1, 2, 2, 25, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1 };
 
@@ -221,7 +225,7 @@ static int process_data(const unsigned char* data)
   default:
     fatal(MYNAME ": Bad internal state\n");
   }
-  state++;
+  ++state;
   return remaining;
 }
 
index 7b032e62905d5728d04b9eaff2ed0e0f95b49066..e084eb2b49ae72499ecfcc427388170ed5c7ea28 100644 (file)
@@ -75,17 +75,27 @@ typedef enum {
   unknown_header
 } header_type;
 
-#if __cplusplus
-inline header_type operator++(header_type& rs, int)
+inline header_type& operator++(header_type& s) // prefix
 {
-  return rs = (header_type)((int)rs + 1);
+  return s = static_cast<header_type>(s + 1);
+}
+inline const header_type operator++(header_type& s, int) // postfix
+{
+  header_type ret(s);
+  s = ++s;
+  return ret;
 }
 
-inline gt_display_modes_e  operator++(gt_display_modes_e& rs, int)
+inline gt_display_modes_e& operator++(gt_display_modes_e& s) // prefix
 {
-  return rs = (gt_display_modes_e)((int)rs + 1);
+  return s = static_cast<gt_display_modes_e>(s + 1);
+}
+inline const gt_display_modes_e operator++(gt_display_modes_e& s, int) // postfix
+{
+  gt_display_modes_e ret(s);
+  s = ++s;
+  return ret;
 }
-#endif
 
 #define MAX_HEADER_FIELDS 36
 
@@ -1002,7 +1012,7 @@ parse_display(const char* str, int* val)
     return 0;
   }
 
-  for (gt_display_modes_e i = GT_DISPLAY_MODE_MIN; i <= GT_DISPLAY_MODE_MAX; i++) {
+  for (gt_display_modes_e i = GT_DISPLAY_MODE_MIN; i <= GT_DISPLAY_MODE_MAX; ++i) {
     if (case_ignore_strcmp(str, gt_display_mode_names[i]) == 0) {
       *val = i;
       return 1;
@@ -1348,7 +1358,7 @@ garmin_txt_rd_init(const QString& fname)
 static void
 garmin_txt_rd_deinit()
 {
-  for (header_type h = waypt_header; h <= unknown_header; h++) {
+  for (header_type h = waypt_header; h <= unknown_header; ++h) {
     free_header(h);
   }
   gbfclose(fin);
diff --git a/igc.cc b/igc.cc
index b0e3df73853abce027d61ac378f1deeb79c6f54d..8ee7b4262589a9502a69892349df04d6f2b8ee9d 100644 (file)
--- a/igc.cc
+++ b/igc.cc
@@ -137,12 +137,16 @@ static void rd_deinit()
 }
 
 typedef enum { id, takeoff, start, turnpoint, finish, landing } state_t;
-#if __cplusplus
-inline state_t operator++(state_t& rs, int)
+inline state_t& operator++(state_t& s) // prefix
 {
-  return rs = (state_t)((int)rs + 1);
+  return s = static_cast<state_t>(s + 1);
+}
+inline const state_t operator++(state_t& s, int) // postfix
+{
+  state_t ret(s);
+  s = ++s;
+  return ret;
 }
-#endif
 
 /**
  * Handle pre- or post-flight task declarations.
@@ -189,7 +193,7 @@ static void igc_task_rec(const char* rec)
     rte_head->rte_name = task_num;
     rte_head->rte_desc = QStringLiteral(DATEMAGIC) + flight_date + QStringLiteral(": ") + task_desc;
     route_add_head(rte_head);
-    state++;
+    ++state;
     return;
   }
   // Get the waypoint
@@ -214,25 +218,25 @@ static void igc_task_rec(const char* rec)
   switch (state) {
   case takeoff:
     snprintf(short_name, 8, "TAKEOFF");
-    state++;
+    ++state;
     break;
 
   case start:
     snprintf(short_name, 8, "START");
     tp_ct = 0;
-    state++;
+    ++state;
     break;
 
   case turnpoint:
     if (++tp_ct == num_tp) {
-      state++;
+      ++state;
     }
     snprintf(short_name, 8, "TURN%02u", tp_ct);
     break;
 
   case finish:
     snprintf(short_name, 8, "FINISH");
-    state++;
+    ++state;
     break;
 
   case landing: